package com.sztx.pay.data.transfer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.sql.Date;
import java.util.Collection;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sztx.commons.httpclient.HttpClientUtil;
import com.sztx.commons.httpclient.HttpHeaderBuilder;
import com.sztx.commons.util.excel.ExcelLogs;
import com.sztx.commons.util.excel.ExcelUtil;
import com.sztx.commons.util.excel.ExcelUtil.ExcelType;
import com.sztx.commons.util.yhbf.YHBFUtil;
import com.sztx.pay.data.transfer.bean.UserInfo;

public class TransferUser {
	
	
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException {				
		
		//100001034
		//83986576
        //getQuickPayCard("100001034");

		
		
		
		
		ExcelLogs logs =new ExcelLogs();
		
		FileInputStream is = new FileInputStream(new File("transfer_user.xlsx"));
		Collection<UserInfo> list = ExcelUtil.importExcel(UserInfo.class, is , null, logs, ExcelType.XSSF, null);
		
		if (list == null || list.isEmpty()) {
			System.out.println("没有用户数据迁移");
			return;
		}
		
		String url = "http://cashier.berbon.com/account/transferUser?userId=%s&isRealName=%s";
		
		for (UserInfo uInfo : list) {			
			System.out.println("正在迁移用户："+uInfo);
			
			String userId = uInfo.getUserId();
			String isRealName = uInfo.getVerified();
			String idNo = uInfo.getIdentityNum();
			String telephone = uInfo.getMob();
			String realName = uInfo.getRealName();
			
			String 	reqUrl = String.format(url, userId, isRealName);
			
			if ("1".equals(isRealName)) {
				reqUrl += "&identityNo="+idNo+"&realName="+realName;				
				if (telephone != null && !telephone.isEmpty()) {
					reqUrl += "&mobileNo="+telephone;
				}
			}
			
			System.out.println(reqUrl);	
			
			HttpClientUtil.get(reqUrl);
		}
				
		System.out.println(list.size());
	}
	
	
	
	
	
	
	
	
	public static void getQuickPayCard(String userId) throws UnsupportedEncodingException{
		
		String url = "http://127.0.0.1:8080/cashier-web/transfer/getQuickPayCard.json?userId="+userId;
		
		HttpHeaderBuilder headerBuilder = HttpHeaderBuilder.custom().accept("application/json");
		String result = HttpClientUtil.get(url, headerBuilder );
		
		JSONObject jObject = JSON.parseObject(result);
		
		
		result = jObject.getJSONObject("resultMap").getString("result");
		
		JSONArray jArray = JSON.parseArray(result);
		
		int size = jArray.size();
		for (int i = 0; i < size; i++) {
			
			jObject = jArray.getJSONObject(i);
			
			Date createTime = new Date(jObject.getLongValue("createTime"));
			Integer identityType = jObject.getInteger("identityType");
			Integer status = jObject.getInteger("status");
			String bankCity = jObject.getString("bankCity");
			Integer primaryFlag = jObject.getInteger("primaryFlag");
			Integer bankChannel = jObject.getInteger("bankChannel");
			String bankName = jObject.getString("bankName");
			String bindNo = jObject.getString("bindNo");
			Integer realBankType = jObject.getInteger("realBankType");
			Integer cardType = jObject.getInteger("cardType");
			
			String bankCard = jObject.getString("bankCard");
			if (bankCard != null && !bankCard.isEmpty()) {
				bankCard = YHBFUtil.decrypt(bankCard);
			}
			
			String bankArea = jObject.getString("bankArea");
			String swiftCode = jObject.getString("swiftCode");
			String identityNo = jObject.getString("identityNo");		
			if (identityNo != null && !identityNo.isEmpty()) {
				identityNo = YHBFUtil.decrypt(identityNo);
			}
			
			String bankType = jObject.getString("bankType");
			String bindType = jObject.getString("bindType");
//			String userId = jObject.getString("userId");
			Date modifyTime = new Date(jObject.getLongValue("modifyTime"));
			String mobileNo = jObject.getString("mobileNo");
			if (mobileNo != null && !mobileNo.isEmpty()) {
				mobileNo = YHBFUtil.decrypt(mobileNo);
			}
			
			
			System.out.println(createTime + " "+identityType+" "+status+" "+bankCity+" "+primaryFlag+" "+bankChannel+" "+bankName+" "+bindNo+" "+realBankType+" "+bankCard);
//			System.out.println(YHBFUtil.decrypt(jObject.getString("bankCard")));
//			System.out.println(YHBFUtil.decrypt(jObject.getString("identityNo")));
		}
		
		
		System.out.println(jArray);
		
		
		
		
		
	}
	
	
	
	

}
